<?php
namespace app\api\controller;

use app\admin\model\xilumarket\order\Order;
use app\common\controller\Api;

class DeliveryUser extends Api{
    // 无需登录的接口,*表示全部
    protected $noNeedLogin = ['orders'];
    // 无需鉴权的接口,*表示全部
    protected $noNeedRight = [];

    public function _initialize() {
        parent::_initialize();
    }
    
    // 历史接单列表
    public function orders() {
        $orders = Order::field("id,order_type,user_id,order_no,pay_type,total_price,pay_price,express_price,freight_type,express_name,express_code,express_no,pay_status,expiretime,freight_status,receipt_status,comment_status,refund_status,order_status,createtime")
        ->with([
            'delivery',
            'seller'=>function($query){
                $query->withField(['id','nickname','avatar']);
            },
            'orderProduct'=>function($query){
                $query->field(['id','order_id','product_id','product_name','image','product_price','sum_price']);
        }])
        ->where(['delivery.user_id' => $this->auth->getUser()->id])->order('delivery.createtime desc')->select();
        return $this->success('获取成功', $orders);
    }
}